package com.gxc.datacore.ws.wsclient;

import java.util.Date;

import com.gxc.datacore.ws.domain.RequestInfo;
import com.gxc.datacore.ws.domain.ResponseInfo;
import com.gxc.datacore.ws.util.XmlUtil;
import com.gxc.webcore.util.StringUtil;

public class QueryClient {

	private static QueryService queryService;

	public static QueryService getQueryService() {
		if (queryService == null) {
			QueryServiceService queryServiceService = new QueryServiceService();
			queryService = (QueryService) queryServiceService
					.getQueryServicePort();
		}
		return queryService;
	}

	public static ResponseInfo query(RequestInfo requestInfo) {
		requestInfo.setId(StringUtil.getUUID());
		requestInfo.setRequest_time(new Date());
		String requestXml = XmlUtil.buildRequestXml(requestInfo);
		String responseXml = queryService.query(requestXml);
		ResponseInfo  responseInfo = null;
		try {
			responseInfo = XmlUtil.parseResponseXml(responseXml);
		} catch (Exception e) {
			responseInfo = new ResponseInfo();
			responseInfo.setId(StringUtil.getUUID());
			responseInfo.setRequest_id(requestInfo.getId());
			responseInfo.setStatus_code("");
			responseInfo.setStatus_name("解析结果失败");
			responseInfo.setResponse_time(new Date());
		}
		return responseInfo;
	}

}
